#自动存取款机系统

# 定义存放账户信息列表的变量
memberList=[
    {"name":"zhangsan","totalmoney":1000},
    {"name":"lisi","totalmoney":100},
    {"name":"wangwu","totalmoney":1500},
    {"name":"zhaoliu","totalmoney":3000}
]
userName=""#定义当前账户名
memberIndex=-1#定义当前账户信息序号
# 定义登陆函数
def login():
    '''
    登陆函数
    '''
    global userName
    while userName == "":
        memberIndex = -1
        inputName = input("请输入您的账户名：")
        for member in memberList:  # 判断输入的用户名是否存在
            memberIndex += 1
            name = member["name"]
            if inputName == name:
                userName = name
                break
        if userName == "":
            print("账户名错误！")
    print("系统登陆成功！")
# 定义查询余额函数
def getTotalMoney(mind):
    '''
    查询余额
    '''
    curinfo = memberList[mind]  # 当前账户信息
    money=curinfo["totalmoney"]
    return money
# 定义存款操作函数
def addMoney(mind):
    '''
    存款操作
    :param mind: 当前账户序号
    '''
    addcount = input("请输入您的存款金额：")
    addcount = float(addcount)
    curinfo = memberList[mind]  # 当前账户信息
    curinfo["totalmoney"] += addcount
    print("存款成功！您的账户总金额：", curinfo["totalmoney"])
# 定义取款操作函数
def minusMoney(mind):
    '''
    取款操作
    :param mind:
    '''
    minusCount = input("请输入您的取款金额：")
    minusCount = float(minusCount)
    curinfo = memberList[mind]  # 当前账户信息
    curinfo["totalmoney"] -= minusCount
    print("取款成功！您的账户总金额：",curinfo["totalmoney"])

# 登陆系统
login()
while True:
    # 输出初始界面
    print("\n","=" * 10, "自动存取款机", "=" * 10)
    print("{:12}{:12}".format("1.查询余额", "2.存款"))
    print("{:14}{:12}".format("3.取款", "4.退出"))
    print("=" * 34)
    # 根据用户输入，执行对应的操作
    key = input("请输入您的选择：")
    if key=="1":
        print("="*8,"查询余额","="*8)
        money=getTotalMoney(memberIndex)
        print("当前账户余额：", money)
    elif key=="2":
        print("="*8,"存款","="*8)
        addMoney(memberIndex)
    elif key=="3":
        print("="*8,"取款","="*8)
        minusMoney(memberIndex)
    elif key=="4":
        print("="*8,"退出","="*8)
        break